package com.example.helloworld;

import java.io.File;

public class DeleteFileDemo {
    public static void main(String[] args) {
        // 这里修改为自己的测试目录
        File folder = new File("C:/Users/47054/Desktop/hello/a");
        deleteFile(folder);
    }
    // 删除文件及目录
    public static void deleteFile(File file) {
        File[] files = file.listFiles();
        if(files != null) {
            for (File f : files) {
               if(f.isDirectory()) {
                   deleteFile(f);
               }else {
                   f.delete();
               }
            }
        }
        file.delete();
    }
}
